For this question, to calculate the fundamental matrix using 8-point algorithm, the following steps were followed:
$F_{teddy} = \begin{bmatrix} 5.91433056e-08 & -2.12678213e-08 & 3.10190612e-04\\ -2.30657434e-07 & -1.45515544e-07 & -1.84284386e-03\\ -8.60754012e-04 & 2.10624262e-03 & 4.64649423e-01 \end{bmatrix}$
$F_{chair} = \begin{bmatrix} -1.88584882e-08 & -3.06155021e-07 & 1.22762898e-04\\ 4.54529423e-07 & -4.40348965e-08 & -2.63156531e-03\\ 5.53598191e-06 & 2.67574197e-03 & -1.50048184e-01 \end{bmatrix}$
For calculating the Essential matrix ($E$), the following steps were followed:
$E_{teddy} = \begin{bmatrix} 0.06272501 & -0.0225558 & 7 0.37052478\\ -0.24462599 & -0.15432793 & -2.16728799\\ -0.90077148 & 2.105036 & -0.01168117 \end{bmatrix}$
$E_{chair} = \begin{bmatrix} -0.01698553 & -0.27574879 & -0.16417522\\ 0.40938717 & -0.03966151 & -2.40478211\\ 0.40921935 & 2.41569513 & -0.06745823 \end{bmatrix}$
The steps followed for computing the fundamnetal matrix using 7 point algorithm as as follows:
$F = \lambda F_1 + (1-\lambda)F_2 \Rightarrow F = \lambda(F_1 - F_2) + F_2$
Let $F_1 - F_2 = F_{coeff}$ and $F_2 = F_{const} \Rightarrow F = \lambda F_{coeff} + F_{const}$
Let $F_{coeff} = \begin{bmatrix} \vec{a_1} & \vec{a_2} & \vec{a_3} \end{bmatrix}$ and $F_{const} = \begin{bmatrix} \vec{b_1} & \vec{b_2} & \vec{b_3} \end{bmatrix}$
Now, the coefficients for the cubic equation in lambda are given as
$A = det(F_{coeff})$
$B = det\begin{pmatrix}\vec{a_1} & \vec{a_2} & \vec{b_3} \end{pmatrix} + det\begin{pmatrix}\vec{a_1} & \vec{b_2} & \vec{a_3} \end{pmatrix} + det\begin{pmatrix}\vec{b_1} & \vec{a_2} & \vec{a_3} \end{pmatrix} $
$C = det\begin{pmatrix}\vec{a_1} & \vec{b_2} & \vec{b_3} \end{pmatrix} + det\begin{pmatrix}\vec{b_1} & \vec{a_2} & \vec{b_3} \end{pmatrix} + det\begin{pmatrix}\vec{b_1} & \vec{b_2} & \vec{a_3} \end{pmatrix} $
$D = det(F_{const})$
$F_{toybus} = \begin{bmatrix} -1.74903938e-06 & 4.22226422e-05 & -6.82374875e-02\\ -6.26047416e-06 & -1.20299872e-04 & 2.34842386e-01\\ 8.17490954e-02 & 1.26366146e-01 & -7.08454540e+01 \end{bmatrix}$
$F_{toytrain} = \begin{bmatrix} 3.66141915e-06 & -8.86148804e-05 & 4.84974472e-02\\ 2.62915797e-05 & -2.24421533e-05 & 7.64438496e-02\\ -1.51307953e-02 & -2.30522700e-02 & -2.80681850e+01 \end{bmatrix}$
The steps followed for 8 point RANSAC are listed below:
The graph and epipolar lines for 8 point can be seen below
$F_{toybus\_RANSAC8} = \begin{bmatrix} -5.07668571e-07 & 2.50841490e-06 & -1.33747166e-03\\ -3.10150685e-06 & -5.28552738e-07 & -5.94904219e-03\\ 1.07023298e-03 & 7.69400029e-03 & 1.00000000e+00 \end{bmatrix}$
$F_{toytrain\_RANSAC8} = \begin{bmatrix} -8.08954167e-06 & 2.83462187e-06 & -1.83412673e-02\\ -1.51324647e-05 & 4.99666641e-06 & -3.39806944e-02\\ 2.30915777e-02 & 3.96680542e-02 & 1.00000000e+00 \end{bmatrix}$
The steps are similar to RANSAC with 8 point, with 1 difference
The graphs and epipolar line visulaization are shown below
$F_{toybus\_RANSAC7} = \begin{bmatrix}-6.43780977e-08 & 4.11962066e-07 & 1.68251299e-04\\ -5.87584608e-07 & 1.05709745e-07 & -4.09276129e-03\\ -7.77023056e-04 & 4.30303151e-03 & 1.00000000e+00 \end{bmatrix}$
$F_{toytrain\_RANSAC7} = \begin{bmatrix}-4.22305732e-06 & -6.37069658e-06 & -6.09514665e-03\\ -4.07259422e-06 & 5.58902765e-06 & -2.25625052e-02\\ 9.78975517e-03 & 2.40012054e-02 & 1.00000000e+00 \end{bmatrix}$
For this question, the steps followed are as follows:
For each point, the 3D point is estimated, by solving a system of linear equations $AX=0$, where $X$ is the 3D point in $\mathbb{P}^3$ and A is the matrix as shown below
It is to be noted, that each point correspondence gives only 4 constraints, so size of $A$ is $4 \times 4$
The point cloud can be seen below (green background is used for contrast)
For bundle adjustment, the following steps are used:
The residual function is defined to return the reprojection error for each pixel in both the images as shown below
The scipy.optimize.least_squares() returns the optimized camera matrices and 3D points
The camera matrices and triangulations before and after BA can be seen below
$P1_{final} = \begin{bmatrix} 1.84416264e+03 & 1.10451211e+02 & -1.79053798e+03 & 2.56000492e+03\\ 3.35919869e+02 & 2.50819410e+03 & 4.64117828e+02 & 2.55995702e+03\\ 9.24442013e-03 & -3.83348980e+00 & 1.60913861e+00 & 1.02039353e+01 \end{bmatrix}$
$P2_{final} = \begin{bmatrix} 2.52397269e+03 & 4.85406968e+00 & -5.38194204e+02 & 2.55671311e+03\\ 8.82947738e+01 & 2.54982532e+03 & 2.82638960e+02 & 2.56708315e+03\\ -4.52630307e-01 & -3.83931532e+00 & 1.95133707e+00 & 1.02436862e+01 \end{bmatrix}$
The input images with the matches and epipolar lines can be seen below